package org.four.merchant.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.four.common.model.CompanyTree;
import org.four.common.model.UserBean;
import org.four.common.model.ZhaoPinBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface ZslMapper {
    @Select("select * from t_com_tree where pid = #{value}")
    List<CompanyTree> findTreeNodes(Integer pid);

    void addZhaoPin(ZhaoPinBean zhaoPinBean);

    int queryZhaoPinCount(HashMap<String, Object> zhaoPinBean);

    List<ZhaoPinBean> queryZhaoPin(HashMap<String, Object> objectObjectHashMap);

    void delZhaoPin(Integer[] id);

    @Select("SELECT count(1) " +
            "FROM t_user_toudi tut " +
            "left join t_user tu on tut.userid = tu.id " +
            "left join t_com_zhaopin tcz on tut.gangweiid=tcz.id " +
            "left join t_user_qiuzhi tuq on tuq.id=tut.jianliid" +
            " where tut.comid = #{value}")
    int queryTouDiCount(Integer id);

    @Select("SELECT tcz.zhiweitype,tcz.touch,tut.id as toudiId,tut.toudistatus,tu.*,tuq.*  " +
            "FROM t_user_toudi tut " +
            "left join t_user tu on tut.userid = tu.id " +
            "left join t_com_zhaopin tcz on tut.gangweiid=tcz.id " +
            "left join t_user_qiuzhi tuq on tuq.id=tut.jianliid " +
            "where tut.comid = #{id}" +
            " limit #{start},#{end}")
    List<UserBean> queryTouDi(@Param("start") int st, @Param("end") int limit,@Param("id") Integer id);

    @Update("update t_user_toudi set toudistatus=#{status} where id =#{id}")
    void updatestatus(@Param("id") Integer id, @Param("status") Integer status);

    @Select("select tcc.count from t_com_chang tcc where tcc.comid = #{value}")
    Integer queryCount(Integer id);

    @Update("update t_com_chang tcc set tcc.count = tcc.count -1 where tcc.comid = #{value}")
    void updateCount(Integer comid);

    /**
     * 招聘按照类型分类
     * @param id
     * @return
     */
    @Select("select count(*) as count from t_com_zhaopin where comid =1  group by worktype")
    List<Map> findComZhaoPin(Integer id);


    @Update("update t_com_zhaopin tcc set tcc.zhidingTime = now() where tcc.id = #{value}")
    void dingdan(Integer id);

    @Update("update t_com_chang tcc set tcc.count = tcc.count+#{count} where tcc.comid = #{id}")
    void addComUserCount(@Param("id") Integer id, @Param("count") Integer count);

    @Select("select tc.count from t_com_chang tc where tc.comid = #{value}")
    Integer findCount(Integer id);

    @Select("select * from t_com_zhaopin where id =#{value}")
    ZhaoPinBean queryById(Integer id);

    @Update("update t_com_zhaopin tczp set tczp.zhidingTime = null where id = #{value}")
    void updateTime(Integer id);
}
